package com.chat.controller;

import com.chat.entry.dto.group.CreateGroupChatDTO;
import com.chat.result.Result;
import com.chat.service.IGroupChatInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 群聊信息表 前端控制器
 * </p>
 *
 * @author
 * @since 2025-08-21
 */
@Api(tags = "群聊信息接口管理")
@RestController
@RequestMapping("/api/group-chat-information")
@Slf4j
@RequiredArgsConstructor
public class GroupChatInformationController {

    private final IGroupChatInformationService groupChatInformationService;

    @ApiOperation(value = "创建群聊", notes = "根据用户id创建群聊")
    @PostMapping("/createGroupChat")
    public Result createGroupChat(
            @ApiParam(value = "创建群聊信息", required = true) @RequestBody CreateGroupChatDTO createGroupChatDTO
    ) {
        return groupChatInformationService.createGroupChat(createGroupChatDTO);
    }

    @ApiOperation(value = "邀请好友进入群聊", notes = "根据用户id邀请好友进入群聊")
    @PostMapping("/{groupChatId}/invite")
    public Result inviteFriendToGroupChat(
            @ApiParam(value = "群聊id", required = true) @PathVariable Integer groupChatId,
            @ApiParam(value = "好友id列表", required = true) @RequestBody List<Integer> userIds
    ) {
        return groupChatInformationService.inviteFriendToGroupChat(groupChatId, userIds);
    }

    @ApiOperation(value = "踢出群聊", notes = "根据用户id踢出群聊")
    @DeleteMapping("/{groupChatId}/remove/{userId}")
    public Result removeGroupChat(
            @ApiParam(value = "群聊id", required = true) @PathVariable Integer groupChatId,
            @ApiParam(value = "被踢出群聊的用户id", required = true) @PathVariable Integer userId
    ) {
        return groupChatInformationService.removeGroupChat(groupChatId, userId);
    }

    @ApiOperation(value = "退出群聊", notes = "根据用户id退出群聊")
    @DeleteMapping("/{groupChatId}/leave/{userId}")
    public Result leaveGroupChat(
            @ApiParam(value = "群聊id", required = true) @PathVariable Integer groupChatId,
            @ApiParam(value = "退出群聊的用户id", required = true) @PathVariable Integer userId
    ) {
        return groupChatInformationService.leaveGroupChat(groupChatId, userId);
    }
}
